﻿using HuiZe.education.Model;
using HuiZe.education.Resource.Controls;
using HuiZe.education.ViewModel;
using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Reflection;
using Spire.Presentation;
using System.IO;
using HuiZe.education.Common;
using Label = System.Windows.Controls.Label;
using HuiZe.education.View.Toolbar;
using Paint;
using System.Collections.Generic;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Drawing;
using System.Windows.Data;
using System.Windows.Media;
using HuiZe.education.View;
using Microsoft.Win32;
using System.Text.RegularExpressions;
using System.Linq;
using System.Diagnostics;
using static HuiZe.education.View.LrcView;
using HuiZe.education.View.AttendClassView;

namespace HuiZe.education.View
{
    /// <summary>
    /// BeginClass26.xaml 的交互逻辑
    /// </summary>
    public partial class BeginClass27 : Window
    {

        //窗口状态
        public class WidState
        {
            public Thickness Margin { get; set; }

            public double Width { get; set; }
        }

        //窗口状态
        WidState normal_state { get; set; }
        WidState full_left_state { get; set; }
        WidState full_right_state { get; set; }
        WidState full_left_right_state { get; set; }
        WidState full_state { get; set; }

        //按钮默认是否打开
        private bool left_open_state { get; set; } = false;
        private bool right_open_state { get; set; } = false;

        public string Current = "";

        public BeginClass27()
        {
            InitializeComponent();

            //var w = new WebBrowserOverlay(this.BdBrowser);
            //var wb = w.WebBrowser;
            //var HelpUrl = "file:\\I:\\wpf_jz111\\huize-edu\\HuiZeOutPut\\ConvertHtmls\\191d0de1296c1c3b1ca34c773c3582df.html";
            //wb.Navigate(new System.Uri(HelpUrl));
            Loaded += ResourceView_Loaded;
        }


        public AttendClassViewModel attendClassView { get; set; }
        public string BkType { get; set; }
        public string BkId { get; set; }

        public string Title { get; set; }
        public string CatName { get; set; }
        public string Class { get; set; }
        public ObservableCollection<ResourceCenterModel> resources { get; set; }
        //BrushToolbar brushToolbar;
        public int PlayBookId = 0;
        //public bool IsFullScreen = false;

        private const int titltHeigth = 36;
        private const int content_max_width = 1300;
        private const int content_normal_width = 1300;

        LnkCanvasToolWid inkcanvasWid = null;
        //InkCanvasTool对象
        InkCanvasTool inkcanvasToolbar;
        private void ResourceView_Loaded(object sender, RoutedEventArgs e)
        {

            //TextMes.Children.Add();
            //TextMes.Children.Add();
            //TextMes.Children.Add();

            attendClassView = DataContext as AttendClassViewModel;
            var beginResList = attendClassView.GetClassResourceDetail(BkId);
            if (beginResList != null)
            {
                int i = 0;
                resList.Children.Clear();
                foreach (var item in beginResList)
                {

                    PlayBookControl playBook = new PlayBookControl
                    {
                        data = item,
                        SourceUrl = item.file,
                        Imageurl = item.image_cover,
                        Imagetxt = item.bname,
                        Width = 471,
                        Height = 50,
                        Margin = new Thickness(5, 5, 0, 0),
                        Id = i,

                    };
                    i++;
                    //playBook.ImageButton.SourceUrl = item.file;
                    playBook.PreviewMouseUp += customButton_Click;
                    //CustomButton customButton = new CustomButton()
                    //{
                    //    Template = (ControlTemplate)FindResource("HZImageButtonTemplate"),
                    //    ImageSource = new BitmapImage(new Uri(item.image_cover)),
                    //    SourceUrl = item.file,
                    //    //MeadiaType
                    //    Content = item.bname,
                    //    Width = 80,
                    //    Height = 40,
                    //    Margin = new Thickness(0, 20, 10, 0),
                    //};
                    //Label label = new Label
                    //{
                    //    Content = item.bname,
                    //    Margin = new Thickness(0, 20, 10, 0),
                    //};
                    //customButton.Click += customButton_Click;


                    resList.Children.Add(playBook);
                    //resList.Children.Add(label);


                }


            }
            this.txt_title.Text = Title;
            this.txt_ct.Text = CatName;
            this.txt_cl.Text = Class;

            //brushToolbar = new BrushToolbar();
            //brushToolbar.kechengbaoId = BkId;

            //ToolbarGrid.Children.Add(brushToolbar);

            ////鼠标左键点击显示InkCanvasTool事件
            //brushToolbar.BruseGrid.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(brushToolbarBruseGrid_MouseLeftButtonUp);

            toolbar.kechengbaoId = BkId;
            toolbar.BackHomeGrid.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(Home_MouseLeftButtonUp);
            toolbar.BruseGrid.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(brushToolbarBruseGrid_MouseLeftButtonUp);
            toolbar.fullScreenGrid.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(fullScreenGrid_MouseLeftButtonUp);

            //上一步
            toolbar.txtNext.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(TxtNext_MouseLeftButtonUp);
            //下一步
            toolbar.txtLast.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(TxtLast_MouseLeftButtonUp);
            toolbar.txtBack.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(TxtBack_MouseLeftButtonUp);

            customButton_Click((resList.Children[0] as PlayBookControl), null);

            //初始化窗口数据
            normal_state = new WidState()
            {
                Margin = new Thickness(320, 0, 320, 0),
                Width = /*this.Width - 320 * 2*/1250
            };

            full_state = new WidState()
            {
                Margin = new Thickness(45, 0, 45, 0),
                Width = this.Width - 45 * 2
            };

            full_left_state = new WidState()
            {
                Margin = new Thickness(320, 0, 45, 0),
                Width = this.Width - 320 - 45
            };
            full_right_state = new WidState()
            {
                Margin = new Thickness(45, 0, 120, 0),
                Width = this.Width - 120 - 45
            };
            full_left_right_state = new WidState()
            {
                Margin = new Thickness(320, 0, 120, 0),
                Width = this.Width - 320 - 120
            };
        }


        private void Home_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {

            ShowDialogView_Ethan showDialogView = new ShowDialogView_Ethan("打开新窗口，可随时返回课程");
            showDialogView.ShowDialog();
            if (showDialogView.DialogResult == false)
            {
                return;
            }

            HuiZeeducation.Instance.Classing = true;

            this.Close();
            MainViewModel mainViewModel = CommonServiceLocator.ServiceLocator.Current.GetInstance<MainViewModel>();
            mainViewModel.OpenMainView();
        }

        private void TxtNext_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (PlayBookId == resList.Children.Count - 1)
            {
                return;
            }
            customButton_Click((resList.Children[PlayBookId + 1] as PlayBookControl), null);


        }


        private void TxtLast_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (PlayBookId == 0)
            {
                return;
            }
            customButton_Click((resList.Children[PlayBookId - 1] as PlayBookControl), null);


        }

        private void MoveTo_Last(object sender, RoutedEventArgs e)
        {
            if (PlayBookId == 0)
            {
                return;
            }
            customButton_Click((resList.Children[PlayBookId - 1] as PlayBookControl), null);
        }

        private void MoveTo_Next(object sender, RoutedEventArgs e)
        {
            if (PlayBookId == resList.Children.Count - 1)
            {
                return;
            }
            customButton_Click((resList.Children[PlayBookId + 1] as PlayBookControl), null);

        }

        private void TxtBack_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            ShowDialogView_Ethan showDialogView = new ShowDialogView_Ethan("是否结束授课");
            showDialogView.ShowDialog();
            if (showDialogView.DialogResult == true)
            {
                HuiZeeducation.Instance.Classing = false;
                this.Close();
            }

        }



        private void fullScreenGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (this.grid_title.Height == 0)
            {
                this.grid_title.Height = titltHeigth;


                this.PART_Media.Width = normal_state.Width;
                this.Content.Margin = normal_state.Margin;

            }
            else
            {
                this.grid_title.Height = 0;
                 updatefullKjState();
            }

            //if (!IsFullScreen)
            //{
            //    this.grid_title.Height = 30;
            //    //fullscreen1.Margin = new Thickness(0, 0, 0, 0);
            //    //fullscreen2.Margin = new Thickness(0, 0, 0, 0);
            //}
            //else
            //{
            //    this.grid_title.Height = 0;
            //    //fullscreen1.Margin = new Thickness(0, 35, 0, 35);
            //    //fullscreen2.Margin = new Thickness(0, 35, 0, 35);

            //}
            //IsFullScreen = !IsFullScreen;
        }

        private void updatefullKjState()
        {
            if (this.grid_title.Height != 0)
            {
                return;
            }

            if (left_open_state && right_open_state)
            {
                this.PART_Media.Width = full_left_right_state.Width;
                this.Content.Margin = full_left_right_state.Margin;
            }
            else if (!left_open_state && right_open_state)
            {
                this.PART_Media.Width = full_right_state.Width;
                this.Content.Margin = full_right_state.Margin;
            }
            else if (left_open_state && !right_open_state)
            {
                this.PART_Media.Width = full_left_state.Width;
                this.Content.Margin = full_left_state.Margin;
            }
            else
            {
                this.PART_Media.Width = full_state.Width;
                this.Content.Margin = full_state.Margin;
            }
        }

        private void Grid_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            //if (this.grid_title.Height == 0)
            //{
            //    this.grid_title.Height = 30;
            //}
            //else
            //{
            //    this.grid_title.Height = 0;
            //}
            //if (e.Key == Key.Escape)//Esc键
            //{
            //    this.grid_title.Height = 0;
            //    //fullscreen1.Margin = new Thickness(0, 35, 0, 35);
            //    //fullscreen2.Margin = new Thickness(0, 35, 0, 35);
            //    IsFullScreen = false;
            //}
            //else if(e.Key == Key.F11)
            //{
            //    fullscreen1.Margin = new Thickness(0, 0, 0, 0);
            //    fullscreen2.Margin = new Thickness(0, 0, 0, 0);
            //}
        }



        #region     手绘工具

        /// <summary>
        /// InkCanvasTool显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void brushToolbarBruseGrid_MouseLeftButtonUp(object sender, RoutedEventArgs e)
        {
            if (inkcanvasWid == null)
            {
                inkcanvasToolbar = new InkCanvasTool();

                //注册事件
                inkcanvasToolbar.Close.Click += inkcanvasToolbarClose_Click;
                inkcanvasToolbar.buttonUndo.Click += inkcanvasToolbarUndo_Click;
                inkcanvasToolbar.buttonDelete.Click += inkcanvasToolbarDelete_Click;

                BindStrategiesToButtons();

                inkcanvasWid = new LnkCanvasToolWid();
                inkcanvasWid.SetContent(inkcanvasToolbar);
                inkcanvasWid.Owner = this;
                inkcanvasWid.ShowInTaskbar = false;
                inkcanvasWid.CanvasRegion.MouseDown += CanvasRegion_MouseDown;
                inkcanvasWid.CanvasRegion.MouseUp += CanvasRegion_MouseUp;
                inkcanvasWid.CanvasRegion.MouseMove += CanvasRegion_MouseMove;

                inkcanvasWid.Show();
                //InkCanvasToolbarGrid.Children.Add(inkcanvasToolbar);


            }
            else if ((inkcanvasWid != null) && (inkcanvasWid.Visibility == Visibility.Hidden))
            {
                inkcanvasWid.Visibility = Visibility.Visible;

                BindStrategiesToButtons();
            }
            else
            {
                return;
            }
        }

        /// <summary>
        /// 关闭InkCanvasTool
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void inkcanvasToolbarClose_Click(object sender, RoutedEventArgs e)
        {
            inkcanvasWid.Visibility = Visibility.Hidden;

            inkcanvasToolbar.buttonHand.IsChecked = false;
            inkcanvasToolbar.buttonLine.IsChecked = false;
            inkcanvasToolbar.buttonRectangle.IsChecked = false;
            inkcanvasToolbar.buttonCircle.IsChecked = false;
            inkcanvasToolbar.buttonTriangle.IsChecked = false;
            inkcanvasToolbar.buttonArrow.IsChecked = false;
            inkcanvasToolbar.buttonText.IsChecked = false;
        }

        /// <summary>
        /// 撤销
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void inkcanvasToolbarUndo_Click(object sender, RoutedEventArgs e)
        {
            if (inkcanvasWid.CanvasRegion.Children.Count >= 1)
            {
                int num = inkcanvasWid.CanvasRegion.Children.Count;

                inkcanvasWid.CanvasRegion.Children.RemoveRange(inkcanvasWid.CanvasRegion.Children.Count - L_num[L_num.Count - 1], L_num[L_num.Count - 1]);
                L_num.RemoveAt(L_num.Count - 1);
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void inkcanvasToolbarDelete_Click(object sender, RoutedEventArgs e)
        {
            if (inkcanvasWid.CanvasRegion.Children.Count >= 1)
            {
                inkcanvasWid.CanvasRegion.Children.Clear();
            }
            L_num.Clear();
        }

        public static IDrawStrategy strategy = null;
        public static Dictionary<ToggleButton, IDrawStrategy> buttonToStrategy;

        public static BrushSettings settings = new BrushSettings();


        private void BindStrategiesToButtons()
        {
            buttonToStrategy = new Dictionary<ToggleButton, IDrawStrategy>();

            buttonToStrategy.Add(inkcanvasToolbar.buttonHand, new DrawByHandStrategy(settings));
            buttonToStrategy.Add(inkcanvasToolbar.buttonLine, new DrawLineStrategy(settings));
            buttonToStrategy.Add(inkcanvasToolbar.buttonCircle, new DrawCircleStrategy(settings));
            buttonToStrategy.Add(inkcanvasToolbar.buttonRectangle, new DrawSquareStrategy(settings));
            buttonToStrategy.Add(inkcanvasToolbar.buttonTriangle, new DrawTriangleStrategy(settings));
            buttonToStrategy.Add(inkcanvasToolbar.buttonArrow, new DrawArrowStrategy(settings));
            buttonToStrategy.Add(inkcanvasToolbar.buttonText, new DrawTextStrategy(settings));

        }


        List<int> L_num = new List<int>();
        int temp;
        private void CanvasRegion_MouseDown(object sender, MouseButtonEventArgs e)
        {
            temp = inkcanvasWid.CanvasRegion.Children.Count;

            strategy?.OnMouseDown(inkcanvasWid.CanvasRegion, e.GetPosition(inkcanvasWid.CanvasRegion));
        }

        private void CanvasRegion_MouseMove(object sender, MouseEventArgs e)
        {
            strategy?.OnMouseMove(inkcanvasWid.CanvasRegion, e.GetPosition(inkcanvasWid.CanvasRegion));
        }

        private void CanvasRegion_MouseUp(object sender, MouseButtonEventArgs e)
        {
            strategy?.OnMouseUp(inkcanvasWid.CanvasRegion, e.GetPosition(inkcanvasWid.CanvasRegion));

            if (inkcanvasWid.CanvasRegion.Children.Count - temp != 0)
            {
                L_num.Add(inkcanvasWid.CanvasRegion.Children.Count - temp);
                temp = 0;
            }
        }

        #endregion



        private void customButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {


            PlayBookControl customButton = sender as PlayBookControl;
            ResBkBeginClassResListModel model = customButton.data as ResBkBeginClassResListModel;

            respResourceChildModel_Ethan data = new respResourceChildModel_Ethan();
            data.id = Convert.ToInt32(model.bid);
            data.resources_name = model.bname;
            data.file = model.file;
            data.ext_name = model.extname;
            data.shownum = 1;
            data.collection = 1;
            data.collectionnum = 1;

            data.res_type_text = model.type;
            data.rotation_img_text = model.rotation_img_text;
            data.lyric_text = model.lyric_text;

            this.PART_Media.Reset();
            this.PART_Media.SetData(data);

            this.PlayBookId = customButton.Id;

        }


        private void close_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            //webBrowser11.Navigate("");
            this.Close();
        }



        private void SourceTree_PreviewMouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {


        }




        private string DownLoadFile(string url, string savepath)
        {
            string extention = Path.GetExtension(url);
            string FileName = Path.GetFileNameWithoutExtension(url);
            string downloadpath = savepath + "\\" + FileName + extention;
            WebApiHelper.Download(url, downloadpath);

            return downloadpath;


        }


        private void exitAddStu_Click(object sender, RoutedEventArgs e)
        {


        }

        System.Windows.Xps.Packaging.XpsDocument xpsDoc;
        public static bool officeFileOpen_Status = false;
        private void OpenSourceFile(string FilePath)
        {

            string xpsFilePath = string.Empty;

            var convertResults = OfficeToXps.ConvertToXps(FilePath, ref xpsFilePath);
            switch (convertResults.Result)
            {

                case ConversionResult.OK:
                    xpsDoc = new System.Windows.Xps.Packaging.XpsDocument(xpsFilePath, FileAccess.Read);
                    officeFileOpen_Status = true;
                    break;

                case ConversionResult.InvalidFilePath:
                    // Handle bad file path or file missing

                    break;
                case ConversionResult.UnexpectedError:

                    // This should only happen if the code is modified poorly
                    break;
                case ConversionResult.ErrorUnableToInitializeOfficeApp:
                    // Handle Office 2007 (Word | Excel | PowerPoint) not installed
                    break;
                case ConversionResult.ErrorUnableToOpenOfficeFile:
                    // Handle source file being locked or invalid permissions
                    break;
                case ConversionResult.ErrorUnableToAccessOfficeInterop:
                    // Handle Office 2007 (Word | Excel | PowerPoint) not installed
                    break;
                case ConversionResult.ErrorUnableToExportToXps:
                    // Handle Microsoft Save As PDF or XPS Add-In missing for 2007
                    break;
            }
        }


        // 预览ppt（使用Presentation插件）
        /// <summary>
        /// ppt转html
        /// </summary>
        /// <returns></returns>
        public string PptToHtml(string url, string savepath)
        {
            var resultUrl = string.Empty;
            var serverUrl = string.Empty;
            string extention = Path.GetExtension(url);
            string FileName = Path.GetFileNameWithoutExtension(url);
            string htmlName = Path.GetFileNameWithoutExtension(url) + ".html";
            String outputFile = Path.GetDirectoryName(savepath) + "\\" + htmlName;
            //实例化Presentation类，加载文件
            Spire.Presentation.Presentation ppt = new Spire.Presentation.Presentation();
            try
            {
                string downloadpath = savepath + "\\" + FileName + extention;
                WebApiHelper.Download(url, downloadpath);

                ppt.LoadFromFile(downloadpath);
                ppt.SaveToFile(outputFile, FileFormat.Html);

                //打开文件

                //保存文件为HTML

            }//`在这里插入代码片`
            catch (Exception ex)
            {
                //this.Write(ex);
            }
            //得到返回的html地址
            resultUrl = Path.GetDirectoryName(savepath) + "\\" + htmlName;
            var lastUrl = Path.GetFileName(resultUrl);
            //resultUrl = ConfigurationManager.AppSettings["ResultUrl"] + lastUrl;
            //serverUrl = ConfigurationManager.AppSettings["ServerUrl"];
            return outputFile;


        }
        #region#pragma warning disable SA1202 // Elements must be ordered by access

        private static readonly DependencyPropertyKey MediaFileNamePropertyKey = DependencyProperty.RegisterReadOnly(
            nameof(MediaFileName),
            typeof(string),
            typeof(BeginClass27),
            new PropertyMetadata(default(string)));

        /// <summary>Identifies the <see cref="MediaFileName"/> dependency property.</summary>
        public static readonly DependencyProperty MediaFileNameProperty = MediaFileNamePropertyKey.DependencyProperty;

        private static readonly DependencyPropertyKey MediaUriPropertyKey = DependencyProperty.RegisterReadOnly(
            nameof(MediaUri),
            typeof(Uri),
            typeof(BeginClass27),
            new PropertyMetadata(default(Uri)));

        /// <summary>Identifies the <see cref="MediaUri"/> dependency property.</summary>
        public static readonly DependencyProperty MediaUriProperty = MediaUriPropertyKey.DependencyProperty;
#pragma warning restore SA1202 // Elements must be ordered by access

        private Stretch stretch;



        public Uri MediaUri
        {
            get => (Uri)this.GetValue(MediaUriProperty);
            protected set => this.SetValue(MediaUriPropertyKey, value);
        }

        public string MediaFileName
        {
            get => (string)this.GetValue(MediaFileNameProperty);
            protected set => this.SetValue(MediaFileNamePropertyKey, value);
        }

        private void OnDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                var files = (string[])e.Data.GetData(DataFormats.FileDrop);
                if (files == null)
                {
                    return;
                }

                if (files.Length > 1)
                {
                    _ = MessageBox.Show(
                        this,
                        "Only onde file at the time can be dropped.",
                        "Error",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);

                    return;
                }

                try
                {
                    this.MediaFileName = files[0];
                    this.MediaUri = new Uri(this.MediaFileName);
                }
                catch (Exception exception)
                {
                    _ = MessageBox.Show(
                        this,
                        exception.Message,
                        "Error",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
        }

        private void OpenExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
            };

            if (openFileDialog.ShowDialog() == true)
            {
                this.MediaFileName = openFileDialog.FileName;
                this.MediaUri = new Uri(this.MediaFileName);
            }
        }

        private void OnToggleFullScreenExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (this.WindowStyle == WindowStyle.SingleBorderWindow)
            {
                this.SetCurrentValue(WindowStyleProperty, WindowStyle.None);
                this.SetCurrentValue(SizeToContentProperty, SizeToContent.Manual);
                this.SetCurrentValue(WindowStateProperty, WindowState.Maximized);
            }
            else
            {
                this.SetCurrentValue(WindowStyleProperty, WindowStyle.SingleBorderWindow);
                this.SetCurrentValue(SizeToContentProperty, SizeToContent.WidthAndHeight);
                this.SetCurrentValue(WindowStateProperty, WindowState.Normal);
            }

            e.Handled = true;
        }

        private void OnEndFullScreenCanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = this.WindowState == WindowState.Maximized && this.WindowStyle == WindowStyle.None;
        }

        private void OnEndFullScreenExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            //this.SetCurrentValue(WindowStyleProperty, WindowStyle.SingleBorderWindow);
            //this.SetCurrentValue(SizeToContentProperty, SizeToContent.WidthAndHeight);
            //this.SetCurrentValue(WindowStateProperty, WindowState.Normal);
            //if (IsFullScreen)
            //{
            //    //fullscreen1.Margin = new Thickness(0, 35, 0, 35);
            //    //fullscreen2.Margin = new Thickness(0, 35, 0, 35);
            //    this.grid_title.Height = 0;
            //    IsFullScreen = false;
            //}
            if (this.grid_title.Height == 0)
            {
                this.grid_title.Height = titltHeigth;
                this.PART_Media.Width = content_normal_width;
            }
            //else
            //{
            //    this.grid_title.Height = 0;
            //}
            //this.grid_title.Height = 0;

            e.Handled = true;
        }

        private void OnMediaFailed(object sender, ExceptionRoutedEventArgs e)
        {
            _ = MessageBox.Show(this, e.ErrorException.Message, "Media failed");
        }
        #endregion





        private void btn_left_open_Click(object sender, RoutedEventArgs e)
        {
            this.btn_left_open.Visibility = Visibility.Hidden;
            this.btn_left_close.Visibility = Visibility.Visible;
            if (this.left_panel.Width == 0)
            {
                this.left_panel.Width = 270;
                this.grid_left_btn_group.Margin = new Thickness(270, 0, 0, 0);
                this.left_open_state = true;
                updatefullKjState();
            }

        }

        private void btn_left_close_Click(object sender, RoutedEventArgs e)
        {

            this.btn_left_open.Visibility = Visibility.Visible;
            this.btn_left_close.Visibility = Visibility.Hidden;
            if (this.left_panel.Width != 0)
            {
                this.left_panel.Width = 0;
                this.grid_left_btn_group.Margin = new Thickness(0, 0, 0, 0);
                this.left_open_state = false;
                updatefullKjState();
            }
        }

        private void btn_right_open_Click(object sender, RoutedEventArgs e)
        {
            this.btn_right_close.Visibility = Visibility.Visible;
            this.btn_right_open.Visibility = Visibility.Hidden;
            if (this.ToolbarGrid.Width == 0)
            {
                //75
                this.ToolbarGrid.Width = 75;
                this.grid_right_btn_group.Margin = new Thickness(0, 0, 75, 0);
                this.right_open_state = true;
                updatefullKjState();
            }
        }

        private void btn_right_close_Click(object sender, RoutedEventArgs e)
        {
            this.btn_right_close.Visibility = Visibility.Hidden;
            this.btn_right_open.Visibility = Visibility.Visible;
            if (this.ToolbarGrid.Width != 0)
            {
                //75
                this.ToolbarGrid.Width = 0;
                this.grid_right_btn_group.Margin = new Thickness(0, 0, 0, 0);
                this.right_open_state = false;
                updatefullKjState();

            }
        }

        private void btn_close_MouseDown(object sender, MouseButtonEventArgs e)
        {
            this.PART_Media.Reset();
            this.Close();
        }
    }
}
